using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace iSay
{
  public partial class ManageFoldersForm : Form
  {
    private readonly List<string> m_folders = new List<string>();

    public ManageFoldersForm(ComboBox.ObjectCollection folders)
    {
      InitializeComponent();
      foreach (string folder in folders)
        Folders.Add(folder);
    }

    public List<string> Folders
    {
      get { return m_folders; }
    }

    private void OnManageFoldersFormLoad(object sender, EventArgs e)
    {
      PopulateTextBox();
    }

    private void Save_Click(object sender, EventArgs e)
    {
      m_folders.Clear();
      string[] separator = new string[] {Environment.NewLine};
      string[] lines = tbFolders.Text.Split(separator, StringSplitOptions.RemoveEmptyEntries);
      foreach (string line in lines)
        m_folders.Add(line);
    }

    private void AddFolder_Click(object sender, EventArgs e)
    {
      using (FolderBrowserDialog browserDialog = new FolderBrowserDialog())
      {
        browserDialog.ShowNewFolderButton = false;
        if (browserDialog.ShowDialog() == DialogResult.OK)
        {
          string folderPath = browserDialog.SelectedPath;
          if (!m_folders.Contains(folderPath))
            m_folders.Add(folderPath);
        }
      }
      PopulateTextBox();
    }

    private void PopulateTextBox()
    {
      tbFolders.Clear();
      foreach (string s in m_folders)
      {
        string folder = string.Format("{0}{1}", s, Environment.NewLine);
        tbFolders.AppendText(folder);
      }
    }

  }
}